Carbon


SetupAIFFHeader

Header: Sound.h Carbon status: Supported

Sets up a file that can subsequently be played by SndStartFilePlay.

OSErr SetupAIFFHeader (
    SInt16 fRefNum, 
    SInt16 numChannels, 
    UnsignedFixed sampleRate, 
    SInt16 sampleSize, 
    OSType compressionType, 
    UInt32 numBytes, 
    UInt32 numFrames
);
Parameter descriptions
fRefNum

A file reference number of a file that is open for writing.

numChannels

The number of channels for the sound; one channel is equivalent to monaural sound and two channels are equivalent to stereo sound.

sampleRate

The rate at which the sound was recorded. The sample rate is declared as a Fixed data type. In order to accommodate sample rates greater than 32 kHz, the most significant bit is not treated as a sign bit; instead, that bit is interpreted as having the value 32,768.

sampleSize

The sample size for the original sound (that is, bits per sample).

compressionType

The compression type for the sound ('NONE', 'MAC3', 'MAC6', or other third-party types).

numBytes

The number of bytes of audio data that are to be stored in the Common Chunk of the AIFF or AIFF-C file.

numFrames

The number of sample frames for the sample sound. If you are using a compression type defined by Apple, you can pass 0 in this field and the appropriate value for this field will be computed automatically.

function result

A result code.

DISCUSSION

The SetupAIFFHeader function creates an AIFF or AIFF-C file header, depending on the parameters passed to it:

The SetupAIFFHeader function might format a sound file as an AIFF file even if the File Manager file type of a file is 'AIFC'. The Sound Manager will still play such files correctly.

The AIFF header information is written starting at the current file position of the file specified by the fRefNum parameter, and the file position is left at the end of the header upon completion. The SetupAIFFHeader function creates a Form Chunk, a Format Version Chunk, a Common Chunk, and a Sound Data chunk, but it does not put any sound data at the end of the Sound Data Chunk.

A good way to use this function is to create a file that you want to store a sound in, then call SetupAIFFHeader with numBytes set to 0 to position the file to be ready to write the audio data. Then record the data to the file, set the file position to the beginning of the file, and call SetupAIFFHeader again with numBytes set to the correct amount of sound data recorded. The file created in this way can be passed to the SndStartFilePlay function to play the sound.

SPECIAL CONSIDERATIONS

If recording produces an odd number of bytes of sound data, you must add a pad byte to make the total number of bytes even.

Because the SetupAIFFHeader function moves memory, you should not call it at interrupt time.

AVAILABILITY

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)